package com.wngbms.leetcode;

import java.util.LinkedList;

public class _32 {

    public static void main(String[] args) {
//        String s = "(()";
//        String s = ")()())";
        String s = "()(()";
//        String s = ")()())";
//        String s = "(";

//        m1(s);

        LinkedList<Character> cs = new LinkedList<>();
        char[] chars = s.toCharArray();
        for (char c : chars) {

            if (!cs.isEmpty()) {


                Character last = cs.getLast();

                // (
                // )
                // num

            }

            cs.addLast(c);

        }
    }

    private static void m1(String s) {
        char[] chars = s.toCharArray();

        int left = 0, right = 0, count = 0, maxRight = 0;

        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];

            if (')' == c) {
                count--;
                if (count >= 0) {
                    right++;
                    maxRight = Math.max(maxRight, right);
                }
            } else {
                if (count < 0) {
                    count = 1;
                    right = 0;
                    left = 1;
                } else {
                    count++;
                    left++;
                }
            }
        }

        if (count <= 0) {
            System.out.println(maxRight * 2);
        } else {
            System.out.println(Math.abs(left - right) * 2);
        }
    }
}
